<?php
function convertTime($string)
{
    $newtime = '';
    $days=floor($string/86400);
    $hours=floor($string%86400/3600);
    $min=floor($string%86400/60)-$hours*60;
    $str="";
    if($days!="0"){
        $str=$str.$days."天";
    }
    if($hours!="0"){
        $str=$str.$hours."时";
    }
    if($min!="0"){
        $str=$str.$min."分";
    }
    return $str;
}
function post_curl_data($url,$xml){
    //CURL模拟请求
    $curls = curl_init(); //启动一个CURL会话
    curl_setopt($curls, CURLOPT_URL, $url); //要访问的地址
    curl_setopt($curls, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($curls, CURLOPT_SSL_VERIFYHOST, FALSE);
    curl_setopt($curls, CURLOPT_HEADER, FALSE);//设置header
    curl_setopt($curls, CURLOPT_RETURNTRANSFER, TRUE);//要求结果为字符串且输出到屏幕上
    curl_setopt($curls, CURLOPT_POST, TRUE); //发送一个常规的Post请求
    curl_setopt($curls, CURLOPT_POSTFIELDS, $xml); //Post提交的数据包
    curl_setopt($curls, CURLOPT_TIMEOUT, 30); //设置超时限制防止死循环
    $payInfo = curl_exec($curls); //执行操作
    //$err = curl_error($curls);//输出错误
    curl_close($curls); //关闭CURL会话
    return $payInfo;
}
function createNoncestr($length = 32){
    $chars = "abcdefghijklmnopqrstuvwxyz0123456789";
    $str = "";
    for ($i = 0; $i < $length; $i++)
    {
        $str .= substr($chars, mt_rand(0, strlen($chars) - 1), 1);
    }

    return $str;
}
function MakeSign($arr,$wxkey){
    //签名步骤一：按字典序排序参数
    ksort($arr);
    $string = ToUrlParams($arr);
    //签名步骤二：在string后加入KEY
    $string = $string . "&key=" . $wxkey;
    //签名步骤三：MD5加密
    $string = md5($string);
    //签名步骤四：所有字符转为大写
    $result = strtoupper($string);
    return $result;
}

//生成签名
function MakeSigns($arr,$wxkey){
    //签名步骤一：按字典序排序参数
    ksort($arr);
    $string = ToUrlParams($arr);
    //签名步骤二：在string后加入KEY
    $string = $string . "&key=" . $wxkey;
    //签名步骤三：MD5加密
    $result = md5($string);
    return $result;
}

//输出xml字符
function ToXml($arr){
    $xml = "<xml>";
    foreach ($arr as $key => $val){
        if (is_numeric($val)){
            $xml .= "<" . $key . ">" . $val . "</" . $key . ">";
        }else{
            $xml .= "<" . $key . "><![CDATA[" . $val . "]]></" . $key . ">";
        }
    }
    $xml .= "</xml>";
    return $xml;
}
//格式化参数格式化成url参数
function ToUrlParams($value){
    $buff = "";
    foreach($value as $k => $v){
        if($k != "sign" && $v != "" && !is_array($v)){
            $buff .= $k . "=" . $v . "&";
        }
    }
    $buff = trim($buff, "&");
    return $buff;
}
function getJson($url){
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $output = curl_exec($ch);
    curl_close($ch);
    return json_decode($output, true);
}
// 应用公共文件
